package com.tzinfo.tzt.activity;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tzinfo.tzt.R;
import com.tzinfo.tzt.util.HttpUtils;
import com.tzinfo.tzt.util.NewsDetailResult;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2014/11/18.
 */
public class CarNewsDetailActivity extends Activity{
    public int id;
    WebView contentTv;
    TextView titleTv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_newsdetail);

        contentTv = (WebView)findViewById(R.id.car_newsdetail_content);
        titleTv = (TextView)findViewById(R.id.car_newsdetail_title);

        Bundle bundle = getIntent().getExtras();
        id = bundle.getInt("Id");
        new GetData().execute();

    }

    class GetData extends AsyncTask<String,Void,NewsDetailResult>{

        @Override
        protected NewsDetailResult doInBackground(String... params) {
            NewsDetailResult result;
            List<NameValuePair> pairs = new ArrayList<NameValuePair>();
            pairs.add(new BasicNameValuePair("Id", ""+id));

            String GetDataUrl = "http://auto.tzinfo.net/mob/api/NewsDetail.ashx";
            String loginResultString = HttpUtils.doPostMethod(GetDataUrl, pairs);

            Gson gson = new Gson();
            result = gson.fromJson(loginResultString, NewsDetailResult.class);
            return result;
        }

        @Override
        protected void onPostExecute(NewsDetailResult result) {
            super.onPostExecute(result);
            contentTv.loadDataWithBaseURL(null,result.getData().getContent().toString(),"text/html","utf-8",null);
            titleTv.setText(result.getData().getTitle().toString());
        }
    }
    public void goBack(View v) {
        this.finish(); //关闭当前Activity
    }
}
